*** compute SW F stats for multiple endogenous variables 


***Inputs: 
* $Data/GameUserWPdaily_norm.dta
* $Data/maxmindirectionsmonth_zip260.dta

***Outputs: 
* $Results/domain_SWF.tex
	
	use $Data/GameUserWPdaily_norm.dta, clear
	
	gen month = month(date)

		
	gen zip2 = int( zip/10)
	
	merge m:1 zip2 month using $Data/maxmindirectionsmonth_zip260.dta
	
	keep if _merge ==3
	
	
	gen monthyear = mofd(date)

	gen highpm =  weighted_dailypm > 25 & weighted_dailypm<. 

	
	
	egen cut_winddirection = cut(median_closestwind), at(0(60)360)
	replace cut_winddirection = 0 if median_closestwind ==360

	
	
	gen maxzipwind = (cut_winddirection ==maxdirection )
	replace maxzipwind = . if maxdirection==.
	
	keep if maxzipwind<. 
	
	
		egen cut_temp = cut(weighted_temperature), at(-40(10)40)

		
		keep norm_score highpm gamenum maxzipwind weighted_wind_speed weighted_precipitation anon_id monthyear cut_temp nth_play
	label variable highpm "Daily PM2.5 $>$ 25" 

	
	
	
	
	
	
	
	
	
foreach x in 55 74 76 77 78 84 104  {
	
	gen highpm_group`x' = highpm* (gamenum ==`x')
	
}




ivreghdfe highpm_group55 (highpm_group74  highpm_group76 highpm_group77 highpm_group78 highpm_group84 highpm_group104  = c.maxzipwind#i.gamenum ) weighted_wind_speed weighted_precipitation , absorb(gamenum anon_id monthyear cut_temp) cluster(anon_id monthyear)

predict pmgroup1hat 

gen pmresid1 = highpm_group55 - pmgroup1hat 

reghdfe pmresid1 c.maxzipwind#i.gamenum weighted_wind_speed weighted_precipitation, absorb(gamenum anon_id monthyear cut_temp) cluster(anon_id monthyear)

test 55.gamenum#c.maxzipwind 74.gamenum#c.maxzipwind 76.gamenum#c.maxzipwind 77.gamenum#c.maxzipwind 78.gamenum#c.maxzipwind 84.gamenum#c.maxzipwind 104.gamenum#c.maxzipwind

scalar FSW1 = r(F)*r(df)/(r(df)-1)
di FSW1


drop pmgroup1hat pmresid1 





ivreghdfe highpm_group74  ( highpm_group55 highpm_group76 highpm_group77 highpm_group78 highpm_group84 highpm_group104  = c.maxzipwind#i.gamenum ) weighted_wind_speed weighted_precipitation , absorb(gamenum anon_id monthyear cut_temp) cluster(anon_id monthyear)


predict pmgroup1hat 

gen pmresid1 = highpm_group74 - pmgroup1hat 

reghdfe pmresid1 c.maxzipwind#i.gamenum weighted_wind_speed weighted_precipitation, absorb(gamenum anon_id monthyear cut_temp) cluster(anon_id monthyear)

test 55.gamenum#c.maxzipwind 74.gamenum#c.maxzipwind 76.gamenum#c.maxzipwind 77.gamenum#c.maxzipwind 78.gamenum#c.maxzipwind 84.gamenum#c.maxzipwind 104.gamenum#c.maxzipwind

scalar FSW2 = r(F)*r(df)/(r(df)-1)
di FSW2








drop pmgroup1hat pmresid1 





ivreghdfe highpm_group76   ( highpm_group55 highpm_group74 highpm_group77 highpm_group78 highpm_group84 highpm_group104  = c.maxzipwind#i.gamenum ) weighted_wind_speed weighted_precipitation , absorb(gamenum anon_id monthyear cut_temp) cluster(anon_id monthyear)


predict pmgroup1hat 

gen pmresid1 = highpm_group76 - pmgroup1hat 

reghdfe pmresid1 c.maxzipwind#i.gamenum weighted_wind_speed weighted_precipitation, absorb(gamenum anon_id monthyear cut_temp) cluster(anon_id monthyear)

test 55.gamenum#c.maxzipwind 74.gamenum#c.maxzipwind 76.gamenum#c.maxzipwind 77.gamenum#c.maxzipwind 78.gamenum#c.maxzipwind 84.gamenum#c.maxzipwind 104.gamenum#c.maxzipwind

scalar FSW3 = r(F)*r(df)/(r(df)-1)
di FSW3










drop pmgroup1hat pmresid1 





ivreghdfe highpm_group77   ( highpm_group55 highpm_group74 highpm_group76  highpm_group78 highpm_group84 highpm_group104  = c.maxzipwind#i.gamenum ) weighted_wind_speed weighted_precipitation , absorb(gamenum anon_id monthyear cut_temp) cluster(anon_id monthyear)


predict pmgroup1hat 

gen pmresid1 = highpm_group77 - pmgroup1hat 

reghdfe pmresid1 c.maxzipwind#i.gamenum weighted_wind_speed weighted_precipitation, absorb(gamenum anon_id monthyear cut_temp) cluster(anon_id monthyear)

test 55.gamenum#c.maxzipwind 74.gamenum#c.maxzipwind 76.gamenum#c.maxzipwind 77.gamenum#c.maxzipwind 78.gamenum#c.maxzipwind 84.gamenum#c.maxzipwind 104.gamenum#c.maxzipwind

scalar FSW4 = r(F)*r(df)/(r(df)-1)
di FSW4







drop pmgroup1hat pmresid1 





ivreghdfe highpm_group78  ( highpm_group55 highpm_group74 highpm_group76 highpm_group77    highpm_group84 highpm_group104  = c.maxzipwind#i.gamenum ) weighted_wind_speed weighted_precipitation , absorb(gamenum anon_id monthyear cut_temp) cluster(anon_id monthyear)


predict pmgroup1hat 

gen pmresid1 = highpm_group78 - pmgroup1hat 

reghdfe pmresid1 c.maxzipwind#i.gamenum weighted_wind_speed weighted_precipitation, absorb(gamenum anon_id monthyear cut_temp) cluster(anon_id monthyear)

test 55.gamenum#c.maxzipwind 74.gamenum#c.maxzipwind 76.gamenum#c.maxzipwind 77.gamenum#c.maxzipwind 78.gamenum#c.maxzipwind 84.gamenum#c.maxzipwind 104.gamenum#c.maxzipwind

scalar FSW5 = r(F)*r(df)/(r(df)-1)
di FSW5








drop pmgroup1hat pmresid1 





ivreghdfe highpm_group84  ( highpm_group55 highpm_group74 highpm_group76 highpm_group77  highpm_group78   highpm_group104  = c.maxzipwind#i.gamenum ) weighted_wind_speed weighted_precipitation , absorb(gamenum anon_id monthyear cut_temp) cluster(anon_id monthyear)


predict pmgroup1hat 

gen pmresid1 = highpm_group84 - pmgroup1hat 

reghdfe pmresid1 c.maxzipwind#i.gamenum weighted_wind_speed weighted_precipitation, absorb(gamenum anon_id monthyear cut_temp) cluster(anon_id monthyear)

test 55.gamenum#c.maxzipwind 74.gamenum#c.maxzipwind 76.gamenum#c.maxzipwind 77.gamenum#c.maxzipwind 78.gamenum#c.maxzipwind 84.gamenum#c.maxzipwind 104.gamenum#c.maxzipwind

scalar FSW6 = r(F)*r(df)/(r(df)-1)
di FSW6










drop pmgroup1hat pmresid1 





ivreghdfe highpm_group104 ( highpm_group55 highpm_group74 highpm_group76 highpm_group77  highpm_group78  highpm_group84     = c.maxzipwind#i.gamenum ) weighted_wind_speed weighted_precipitation , absorb(gamenum anon_id monthyear cut_temp) cluster(anon_id monthyear)


predict pmgroup1hat 

gen pmresid1 = highpm_group104 - pmgroup1hat 

reghdfe pmresid1 c.maxzipwind#i.gamenum weighted_wind_speed weighted_precipitation, absorb(gamenum anon_id monthyear cut_temp) cluster(anon_id monthyear)

test 55.gamenum#c.maxzipwind 74.gamenum#c.maxzipwind 76.gamenum#c.maxzipwind 77.gamenum#c.maxzipwind 78.gamenum#c.maxzipwind 84.gamenum#c.maxzipwind 104.gamenum#c.maxzipwind

scalar FSW7 = r(F)*r(df)/(r(df)-1)
di FSW7






matrix Fstats = [FSW1 , FSW2, FSW3, FSW4, FSW5,FSW6 ,FSW7]'


estout matrix(Fstats) using $Results/domain_SWF.tex, replace





